

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @author:cai
 * @date:2022-05-17-10:18
 */
public class write {
    public static void File_write() throws IOException {



        Date date = new Date();

        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        String str = format.format(date);
        File file = new File("H://date/"+File_name.name+"---"+File_name.title+"---"+str+File_name.weather+".txt" );
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("文件已创建");
        } else {
            System.out.println("文件已存在,已追加内容");
        }
        System.out.println("输入内容");
        try
        {
            Scanner sc = new Scanner(System.in);
            String content=sc.next();
            FileOutputStream out=new FileOutputStream(file,true);
            out.write(content.getBytes());

        }

        catch (FileNotFoundException e)
        {

            System.out.println("文件不存在或者文件不可读或者文件是目录");
        }
        catch (IOException e)
        {
            System.out.println("读取过程存在异常");
        }
        System.out.println("===========输入完成！=============");
        System.out.println("已经返回菜单！1，写日记    2.读取日记");


    }
}
